//截取url参数部分字符串
function getUrlParams (urlStr) {
  var StartIdx = urlStr.indexOf("?")
  if(StartIdx != -1){
    var endIdx = urlStr.length
    var params = urlStr.substring(StartIdx, endIdx)
  }else {
    var params = ''
  }
    return params

}

//把url参数转对象
function readUrlToParams (url) {
  var nameValue;
  var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
  var paraObj = {};
  for (var i = 0; nameValue = paraString[i]; i++) {
  var name = nameValue.substring(0, nameValue.indexOf("=")).toLowerCase();
  var value = nameValue.substring(nameValue.indexOf("=") + 1, nameValue.length);
  if (value.indexOf("#") > -1) {
  value = value.split("#")[0];
  }
  paraObj[name] = value;
  }
  return paraObj;
};

// 去官网
function toWebsite (toUrl, params) {
  if(params){
    params = getUrlParams(window.location.href)
    window.open(toUrl + params, '_blank')
    // window.location.href = toUrl + params
  }else {
    window.open(toUrl + params, '_blank')
    // window.location.href = toUrl + params
  }

}

// 判断是否ios或安卓

function mobelType (isAndroid, isIos, noAll) {
  var u = navigator.userAgent;
  if (u.indexOf('Android') > -1 || u.indexOf('Adr') > -1) {
      isAndroid();
  } else if (!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
      isIos();
  }else {
  	noAll()
  }
}

  /*判断微信或不是微信*/
function isWachat (isisWachat, isweibo, notWachat) {
  var ua = window.navigator.userAgent.toLowerCase();
  if (ua.match(/MicroMessenger/i) == 'micromessenger') {
    isisWachat();
  } else if(ua.match(/WeiBo/i) == "weibo"){
    isweibo();
  } else {
    notWachat();
  }
}

// 统计相关函数
function Statistics(type){
  if($(".Statistics-img")){
      $(".Statistics-img").remove()
  }

  var phonetype
  mobelType(function(){
    phonetype = "&phonetype="+ type + "&download=1"
  }, function(){
    phonetype = "&phonetype="+ type + "&download=1"
  }, function(){
    phonetype = "&phonetype="+ type + "&download=1"
  })

  var url = window.location.href
  var StartIdx = url.indexOf("?")
  if(StartIdx != -1){
      var endIdx = url.length
      var params = url.substring(StartIdx, endIdx)
      var imgElment = "<img class='Statistics-img' src='http://www.zbqibing.com/ld/images/Statistics.png" + params + phonetype + "&random=" + Math.random() + "' alt='统计专用'>"
      $("body").append(imgElment)
  }
}


// 回到顶部

$(function(){
  $(window).scroll(function(){
     var sc=$(window).scrollTop();
     var rwidth=$(window).width()
     if(sc>0){
      $(".goTopBtn").css("display","block");
      // $("#goTopBtn").css("left",(rwidth-36)+"px")
     }else{
     $(".goTopBtn").css("display","none");
     }
   })
   $(".goTopBtn").on("click", function(){
     var sc=$(window).scrollTop();
     $('body,html').animate({scrollTop:0},500);
   })
})


function getDownLoadUrl (url){
   var adFromData = {
      "10": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=10&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_10.apk"
      },
      "11": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=11&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_11.apk"
      },
      "12": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=12&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_12.apk"
      },
      "13": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=13&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_13.apk"
      },
      "18": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=18&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_18.apk"
      },
      "19": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=19&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_19.apk"
      },
      "20": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=20&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_20.apk"
      },
      "21": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=21&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_21.apk"
      },
      "22": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=22&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_22.apk"
      },
      "25": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=25&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_25.apk"
      },
      "26": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=26&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_26.apk"
      },
      "27": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=27&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_27.apk"
      },
      "28": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=28&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_28.apk"
      },
      "29": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=29&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_29.apk"
      },
      "30": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=30&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_30.apk"
      },
      "31": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=31&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_31.apk"
      },
      "32": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=32&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_32.apk"
      },
      "41": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=41&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_41.apk"
      },
      "42": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=42&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_42.apk"
      },
      "43": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=43&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_43.apk"
      },
      "44": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=44&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_44.apk"
      },
      "45": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=45&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_45.apk"
      },
      "46": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=46&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_46.apk"
      },
      "47": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=47&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_47.apk"
      },
      "48": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=48&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_48.apk"
      },
      "49": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=49&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_49.apk"
      },
      "50": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=50&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_50.apk"
      },
      "51": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=51&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_51.apk"
      },
      "52": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=52&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_52.apk"
      },
      "53": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=53&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_53.apk"
      },
      "54": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=54&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_54.apk"
      },
      "01": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=1&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_1.apk"
      },
      "06": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=6&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_6.apk"
      },
      "08": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=8&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_8.apk"
      },
      "09": {
          "ios": "https://itunes.apple.com/app/apple-store/id1253939312?pt=118821653&ct=9&mt=8",
          "android": "http://action.ihaveu.com/downloadapp/card/android/jiagu/CardGame_9.apk"
      }
  }
  var adFrom = readUrlToParams(url).ad_from
  adFrom = '' + adFrom
  if(adFrom!='' && adFromData[adFrom]){
    return adFromData[adFrom]
  }else {
    return {
      ios: "https://itunes.apple.com/app/id1253939312",
      android: "http://action.ihaveu.com/downloadapp/card/android/CardGame.apk" 
    }
  }
}